<?php
    header('Access-Control-Allow-Origin: *');
	header("Access-Control-Allow-Method:POST,GET");
    header ( "Content-Type: text/html; charset=UTF-8" );
    require_once 'mysql.function.php';
	require_once 'response.class.php';
    $rawPostData = file_get_contents("php://input");
	$postData = json_decode($rawPostData,true);
      

     for ($x=0; $x<10; $x++) {
         if($postData["$x"]["id_"] == 1){
         	$id = $postData["$x"]["id"];
	        $comment = $postData["$x"]["sentWord"];
         } 
      } 
	 


	 function getIp(){
		if (getenv("HTTP_CLIENT_IP"))
			$ip = getenv("HTTP_CLIENT_IP"); 
		else if(getenv("HTTP_X_FORWARDED_FOR"))
			$ip = getenv("HTTP_X_FORWARDED_FOR"); 
		else if(getenv("REMOTE_ADDR")) 
			$ip = getenv("REMOTE_ADDR"); 
		else
			$ip = time().rand(0,100);
		return $ip;
	}
	$ip = getIp();

	if (empty($comment)) {
        $message = array(
        	'content' => '提交的内容不能为空',
        	);
        $re = new Response();
		$re->show(200,'fail',$message);
       }

   /*   if (empty($id)) {
        $message = array(
        	'content' => '找不到对应序号',
        	);
        $re = new Response();
		$re->show(200,'fail',$message);
       }*/

       $sqlhelper = new sqlhelper();
       $array = array('treecomment'=>$comment,'ip'=>$ip,'id'=>$id);
	   $table = "TreeComment";
	   $affectedRows = $sqlhelper->insert($table,$array);
	   $sqlhelper->close_connect();

	   $re = new Response();
	if($affectedRows > 0){
		$message = array(
			'content'=>'提交数据成功',
		);
		$re->show(200,'success',$message);
	}else{
		$message = array(
			'content'=>'提交数据失败,请@留言,联系公众号~',
		);
		$re->show(200,'fail',$message);
	}
	exit();
        
?>